package com.fjc.controller;

import com.alibaba.fastjson.JSONObject;
import com.fjc.domain.ResultObject;
import com.fjc.domain.SysRole;
import com.fjc.service.SysRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class SysRoleController {
    private final static Logger logger = LoggerFactory.getLogger(SysRoleController.class);
    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("getRoles")
    public ResultObject getRoles(Integer page, Integer limit){
        logger.info("角色信息page:" + page + " limit:" + limit);
        return sysRoleService.getRoles(page,limit);
    }

    @GetMapping("delRole")
    public ResultObject delRole(Integer id){
        logger.info("删除角色" + id);
        return sysRoleService.delRole(id);
    }

    @PostMapping("saveRole")
    public ResultObject saveRole(SysRole sysRole){
        logger.info("保存角色" + sysRole);
        return sysRoleService.saveRole(sysRole);
    }

    @GetMapping("getRolePermissions")
    public ResultObject getRolePermissions(Integer id){
        logger.info("获取用户权限树" + id);
        return sysRoleService.getRolePermissions(id);
    }

    @PostMapping("updatePermissionsByRoleId")
    public ResultObject updatePermissionsByRoleId(@RequestBody JSONObject object){
        logger.info("更新用户权限树" + object);
        return sysRoleService.updatePermissionsByRoleId(object);

    }

}
